package com.springapp.dao.dao.impl;

import com.springapp.dao.dao.IParametreDAO;
import com.springapp.model.Article;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Qualifier;
import org.springframework.stereotype.Repository;

import javax.sql.DataSource;
import java.sql.Connection;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.sql.SQLException;

/**
 * Created by nicol_000 on 01/09/14.
 */
@Repository
public class ParametreDAO implements IParametreDAO {
    @Qualifier("dataSource") //Fait référence au datasource dans le mvc-dispatcher.xml
    @Autowired
    private DataSource dataSource;

    @Override
    public float getDelaisJourSecurite(){
        float fdelais = 0;

        String req = "SELECT DelaisJourSecurite\n"+
                     "FROM PARAMETRE";

        Connection conn=null;
        try {
            conn=dataSource.getConnection();
            PreparedStatement ps = conn.prepareStatement(req);
            ResultSet result=ps.executeQuery();
            while(result.next()){
                if(result != null)
                {
                   fdelais = result.getFloat("DelaisJourSecurite");
                }
            }
            result.close();
            ps.close();

        } catch (SQLException e) {
            e.printStackTrace();
        }

        return fdelais;
    }
}
